package Pattern;

import java.util.Vector;

import Basics.Atom;
import Basics.Constant;
import Basics.Program;
import Basics.Rule;
import Basics.Var;
import Derivation.SemiNaive;
import Parsing.ParseDB;

public class DebugPattern 
{
	public static void main (String [] args)
	{
		ParseDB rfDB = new ParseDB ("C:\\Users\\amirgilad\\Downloads\\yago2core_facts.clean.notypes.tsv", 1000);
		Var a = new Var("a", "Country");
		Var b = new Var("b", "Country");
		Var c = new Var("c", "Product");
		Var f = new Var("f", "Country");
		
		Atom dealsWith1_1 = new Atom("dealsWith", a,b);
		Atom dealsWith1_2 = new Atom("dealsWith", a,b);
		Atom dealsWith1_3 = new Atom("dealsWith", a,b);
		Atom dealsWith2 = new Atom("dealsWith", a,f);
		Atom dealsWith3 = new Atom("dealsWith", f,b);
		Atom dealsWith4 = new Atom("dealsWith", b,a);
		Atom exports = new Atom("exports", b,c);
		Atom imports = new Atom("imports", a,c);
		
		
		Rule r1 = new Rule (dealsWith1_1, 1, imports, exports);
		Rule r2 = new Rule (dealsWith1_2, 1, dealsWith2, dealsWith3);
		Rule r3 = new Rule (dealsWith1_3, 1, dealsWith4);
		
		Program prog = new Program(r1, r2, r3);
		
		Constant Cuba = new Constant("Cuba", "Country");
		Constant France = new Constant("France", "Country");
		//Constant Mexico = new Constant("Mexico", "Country");
		Constant cigars = new Constant("cigars", "Product");
		//Constant wine = new Constant("wine", "Product");
		
		/*Atom exFw = new Atom ("exports",true, true, France, wine);
		Atom exCc = new Atom ("exports",true, true, Cuba, cigars);
		Vector<Atom> v1 = new Vector<Atom>(); 
		v1.add(exFw);
		v1.add(exCc);
		
		Atom imCw = new Atom ("imports",  true, true, Cuba, wine);
		Atom imMw = new Atom ("imports",  true, true, Mexico, wine);
		Atom imMc = new Atom ("imports",  true, true, Mexico, cigars);
		Atom imFc = new Atom ("imports", true, true, France, cigars);
		Vector<Atom> v2 = new Vector<Atom>(); 
		v2.add(imCw);
		v2.add(imMw);
		v2.add(imMc);
		v2.add(imFc);
		
		Map<String, Vector<Atom>> d = new HashMap<String, Vector<Atom>>();
		d.put("exports", v1);
		d.put("imports", v2);*/
		
		PatternNode root = new PatternNode ("dealsWith",false, Cuba, France);
		PatternNode child1 = new PatternNode ("dealsWith",false, France, Cuba);
		PatternNode grandchild1 = new PatternNode ("exports", false, Cuba, cigars);
		//PatternNode grandchild2 = new PatternNode ("exports",false, Cuba, cigars);
	
		root.setChildren(child1);
		child1.setParent(root); 
		child1.setChildren(grandchild1);
		grandchild1.setParent(child1);
		//child1.setChildren(grandchild);
		
		Vector<PatternNode> rootVec = new Vector<PatternNode> ();
		rootVec.add(root);
		
		Vector<PatternNode> childVec = new Vector<PatternNode> ();
		childVec.add(child1);
		//childVec.add(child2);
		
		Vector<PatternNode> grandChildVec = new Vector<PatternNode> ();
		grandChildVec.add(grandchild1);
		
		Vector<Vector<PatternNode>> pattern = new Vector<Vector<PatternNode>> ();
		pattern.add(rootVec); 
		pattern.add(childVec); 
		pattern.add(grandChildVec);
		
		IntersectWithProgram iwp = new IntersectWithProgram (prog, pattern);
		iwp.getPattern().Renaming();
	
		/*//check renaming
		System.out.println(iwp.getPattern().getPatternVec().get(2).get(0).getNewName());
		
		//check isIdb
		System.out.println(iwp.getPattern().getPatternVec().get(1).get(0) + " is idb? " + 
				iwp.getPattern().getPatternVec().get(1).get(0).IsNodeRelationEdb(new Program(r1, r2, r3)));
		
		//check InDB
		System.out.println("in DB? " + iwp.getPattern().getPatternVec().get(1).get(0).InDb(d2));
		*/
		
		//check intersect
		/*System.out.println(iwp.getPattern());
		System.out.println(iwp.getP());
		iwp.IntersectNoTransitives();
		System.out.println(iwp.getP());
		System.out.println("DB: ");
		iwp.getDb().Print();*/
		
		/*SemiNaive sn = new SemiNaive(iwp.getDb(), iwp.getP());
		sn.Run();*/
		
		/*SemiNaive sn = new SemiNaive(prog);
		sn.Run(true);
		Program p2 = new Program(sn.getParser().getConstantsProgram());*/
		IntersectWithProgram iwp2 = new IntersectWithProgram (prog, pattern);
		System.out.println(iwp2.getPattern());
		System.out.println(iwp2.getP());
		iwp2.IntersectNoTransitives();
		System.out.println(iwp2.getP());
		System.out.println("DB: ");
		/*TopDown td = new TopDown(iwp.getDb(), iwp.getP());
		
		root.getInstAtom().setName(root.getNewName());
		
		td.Run(root.getInstAtom());
		System.out.println("provenance: " + td.getParser().getProvenance());*/
	}
	
	
}
